#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/epoll.h>
#include <fcntl.h>
#include <stdio.h>


int main()
{

    int epfd = epoll_create(100);
    if (-1==epfd)
    {
        printf("创建epoll失败：%m\n");
        exit(-1);
    }

    printf("创建epoll成功\n");

    struct epoll_event ev={0};
    ev.events=EPOLLIN;
    ev.data.fd = 0;

    int r = epoll_ctl(epfd,EPOLL_CTL_ADD,0,&ev);
    if (-1==r)
    {
        printf("创建epoll事件失败:%m\n");
        exit(-1);
    }

    printf("注册epoll事件成功\n");


    char buff[1024];
    struct epoll_event evs[100]={0};
    int n;
    while (1)
    {
        n=epoll_wait(epfd,evs,100,0);
        if (n<0)
        {
            printf("epoll_wait失败：%m\n");
            close(epfd);
            exit(-1);
        }else if (n==0)
        {
            //printf("没动静\n");
            continue;
        }else
        {
           // printf("有动静:%d\n",n);

            for (int i=0;i<n;i++)
            {
                if (0==evs[i].data.fd)
                {
                    scanf("%s",buff);
                    printf(">>%s\n",buff);
                }
            }
        }
    }

    return 0;
}